package com.angelababy.order.listener;

import com.alibaba.fastjson.JSON;
import com.angelababy.order.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RabbitListener(queues = "order_pay")
public class OrderPayListener {
    @Autowired
    private OrderService orderService;

    @RabbitHandler
    public void updatePayStatus(String message) {
        Map map = JSON.parseObject(message, Map.class);
        //调用业务层,完成订单数据库的修改
        orderService.updatePayStatus((String) map.get("orderId"),(String) map.get("transactionId"));
    }
}
